package utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBconn {
	
	  private static final String URL = "jdbc:mysql://localhost:3306/javaweb";
	  private static final String USER = "root";
	  private static final String PASSWORD = "123456";

	//数据库连接：考虑过要不要单独写，但
	public static Connection getConnection() throws SQLException {
		try {
			Class.forName("com.mysql.cj.jdbc.Driver");
			return DriverManager.getConnection(URL, USER, PASSWORD);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			throw new SQLException("MySQL JDBC driver not found.", e);
		}
		 
		 
		} 
	  // 关闭连接
    public static void closeConnection(Connection conn) {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    
   }

}
